package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpProductClassifyBo;
import com.erp.gather.domain.vo.ErpProductClassifyVo;
import com.erp.gather.service.IErpProductClassifyService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 商品分类标签;参考数据字典ERP_PRODUCT_CLASSIFY
 *
 * @author erp
 * @date 2023-03-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/productClassify")
public class ErpProductClassifyController extends BaseController {

	private final IErpProductClassifyService iErpProductClassifyService;

	@GetMapping("/getSelectList")
	public R<Object> getSelectList() {
		List<ErpProductClassifyVo> list = iErpProductClassifyService.queryList(new ErpProductClassifyBo());
		List<Map<String, Object>> collect = list.stream().map(vo -> {
			Map<String, Object> map = new HashMap<>();
			map.put("lable", vo.getName());
			map.put("value", vo.getId());
			return map;
		}).collect(Collectors.toList());
		return R.ok(collect);
	}

	/**
	 * 查询商品分类标签;参考数据字典ERP_PRODUCT_CLASSIFY列表
	 */
	@GetMapping("/list")
	public TableDataInfo<ErpProductClassifyVo> list(ErpProductClassifyBo bo, PageQuery pageQuery) {
		return iErpProductClassifyService.queryPageList(bo, pageQuery);
	}

	/**
	 * 获取商品分类标签;参考数据字典ERP_PRODUCT_CLASSIFY详细信息
	 *
	 * @param id 主键
	 */
	@GetMapping("/{id}")
	public R<ErpProductClassifyVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
		return R.ok(iErpProductClassifyService.queryById(id));
	}

	/**
	 * 新增商品分类标签;参考数据字典ERP_PRODUCT_CLASSIFY
	 */
	@RepeatSubmit()
	@PostMapping()
	public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpProductClassifyBo bo) {
		return toAjax(iErpProductClassifyService.insertByBo(bo));
	}

	/**
	 * 修改商品分类标签;参考数据字典ERP_PRODUCT_CLASSIFY
	 */
	@RepeatSubmit()
	@PutMapping()
	public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpProductClassifyBo bo) {
		return toAjax(iErpProductClassifyService.updateByBo(bo));
	}

	/**
	 * 删除商品分类标签;参考数据字典ERP_PRODUCT_CLASSIFY
	 *
	 * @param ids 主键串
	 */
	@DeleteMapping("/{ids}")
	public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
		return toAjax(iErpProductClassifyService.deleteWithValidByIds(Arrays.asList(ids), true));
	}
}
